<?php


class UserAction extends CommonAction
{
	
	//基本信息
	public function index()
    {
		$user = M('user');
		$this->assign("current_user_index",'current');
		$user_id = $_SESSION['user_id'];
		$userinfo = $user->where('user_id='.$user_id)->find();
		$catyarray = CityArray();
		$this->assign("userinfo",$userinfo);
		$this->assign("catyarray",$catyarray);
		$this->display();
    }
	
	function doIndex()
	{
		$user = M('user');
		$user_id = $_SESSION['user_id'];
		$data['user_name'] = $_POST['username'];
		$data['user_rname'] = $_POST['realname'];
		$data['user_country'] = $_POST['province'];
		$data['user_postcode'] = $_POST['postcode'];
		$data['user_address'] = $_POST['address'];
		$data['user_time'] = time();
		if(!empty($_POST['username']) && !empty($_POST['province']) && !empty($_POST['realname']))
		{
			$addUser = $user->where("user_id=".$user_id)->save($data);
			if(!empty($addUser))
			{
				echo 1;		
			}
			else
			{
				echo 2;			
			}
		}
		else
		{
			echo 0;	
		}
		exit;		
	}
	
	//联系方式
	function userContact()
	{
		$user = M('user');
		$this->assign("current_user_contact",'current');
		$user_id = $_SESSION['user_id'];
		$userinfo = $user->where('user_id='.$user_id)->find();
		$catyarray = CityArray();
		$this->assign("userinfo",$userinfo);
		$this->assign("catyarray",$catyarray);
		$this->display();	
	}
	
	function doContact()
	{		
		$user = M('user');
		$user_id = $_SESSION['user_id'];
		$data['user_phone'] = $_POST['user_phone'];
		$data['user_qq'] = $_POST['user_qq'];
		$data['user_msn'] = $_POST['user_msn'];
		$data['user_email'] = $_POST['user_email'];
		if(!empty($_POST['user_phone']) && !empty($_POST['user_qq']) && !empty($_POST['user_email']))
		{
			$addContactInfo = $user->where("user_id=".$user_id)->save($data);
			if($addContactInfo)
			{
				echo 1;		
			}
			else
			{
				echo 2;			
			}
		}
		else
		{
			echo 0;	
		}
		exit;
	}
	
	//密码修改
	function changePsw()
	{
		$this->assign("current_user_changepsw",'current');
		
		$this->display();	
	}
	function doPsw()
	{
		$user = M('user');
		$user_id = $_SESSION['user_id'];
		$oldpsw = md5($_POST['user_oldpsw']);
		$user_newpsw = $_POST['user_newpsw'];
		$user_renewpsw = $_POST['user_renewpsw'];
		$user_pswto = md5($_POST['user_renewpsw']);
		
		$user_psw = $user->where("user_id=".$user_id)->getField('user_psw');
		if( $oldpsw == $user_psw)
		{
			 if($user_newpsw == $user_renewpsw )
			 {
				$re = $user->where("user_id=".$user_id)->setField('user_psw',$user_pswto); 
				if($re)
				{
					echo 1;
				}
				else
				{
					echo 2;	
				}
			 }
			 else
			 {
				echo 2;	 
			 }
		}
		else
		{
			echo 2;	
		}
		
		exit;
	}	
//	function informSetting()
//	{
//		$this->assign("current_user_inform",'current');
//		
//		$this->display();	
//	}	
//	function emailRemind()
//	{
//		$this->assign("current_user_email",'current');
//		
//		$this->display();	
//	}	
}



?>